package com.mo.demo.guava;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class GuavaWeekTest {
    public static void main(String[] args) throws InterruptedException {

        Cache<String, Object> cache = CacheBuilder.newBuilder()
                .weakValues()
                .build();

        Object value = new Object();

        cache.put("1",value);

        value = null;

        System.gc();

        log.info("value={}",cache.getIfPresent("1"));

        // 输出：
        // 13:25:29.957 [main] INFO com.mo.demo.guava.GuavaWeekTest - value=null

    }
}
